<template>
	<view class="meface">
		<view class="imgchoose">
			<image :src="imgurl" mode="" class="face"></image>
			 <cropper class="face" selWidth="660rpx" selHeight="660rpx"
			          @upload="myUpload" :avatarSrc="imgurl"
			          avatarStyle="width:120rpx;height:120rpx;border-radius:50%;">
			  </cropper>
		</view>
		<view class="btns">
			<view class="leftbtn" :class="{trunyello:istrunyellow1}" @click="rechoose">
				重新选择
			</view>
			<view class="rightbtn" :class="{trunyello:istrunyellow2}" @click="surechoose">
				确认上传
			</view>
		</view>
	</view>
</template>

<script>
	import common from '../../common/common.js';
	import copper from '../imgupdata/imgupdata'
	export default {
		data() {
			return {
				istrunyellow1:false,
				istrunyellow2:false,
				imgurl:""
			}
		},
		onLoad(e) {
			console.log(e)
			this.imgurl =e.imgurl
			
		},
		components:{
			copper
		},
		methods: {
			rechoose(){
				var me = this
				this.istrunyellow1 = true,
				this.istrunyellow2 = false,
				uni.chooseImage({
				    count: 1, //默认9
				    sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
				    sourceType: ['album'], //从相册选择
				    success: function (res) {
						me.imgurl = res.tempFilePaths[0]
						me.istrunyellow1 = false
				    }
				});
			},
			surechoose(){
				this.istrunyellow2 = true
				this.istrunyellow1 = false
				var me = this 
				var globalUser = me.getGlobalUser("globaluser")
				console.log(globalUser)
				uni.showLoading({
					mask:true,
					title:"头像上传中..."
				})
				uni.request({
					url:common.serverUrl+'/user/uploadFace?userId='+globalUser.id,
					filePath:me.imgurl,
					name:"file",
					success(res) {
						globalUser.faceImages = me.imgurl
						uni.setStorageSync("globaluser",globalUser)
						uni.hideLoading()
						uni.navigateBack({
							delta:1
						})
					}
				})
				
			}
		}
	}
</script>

<style>
@import url("./meface.css");
</style>
